package com.example.spring.util;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author yanzhao
 * @date 2022/11/10 21:37
 * @since 1.0.0
 */
public class ProxyUtil {

    public static <T> T getProxy(Class<T> sourceClass) {
        return (T) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class[]{sourceClass},
                new InvocationHandler() {
                    @Override
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                        return "Proxy$" + sourceClass.getSimpleName();
                    }
                });
    }
}
